{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HW1_ZTT_AME_House线性回归分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1432 entries, 0 to 1431\n",
      "Columns: 286 entries, MSZoning_1 to SalePrice\n",
      "dtypes: float64(3), int64(283)\n",
      "memory usage: 3.1 MB\n"
     ]
    }
   ],
   "source": [
    "train=pd.read_csv('train_fin_ztt.csv')\n",
    "test=pd.read_csv('test_fin_ztt.csv')\n",
    "\n",
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1432, 284)"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train=train['SalePrice'].values\n",
    "train_id=train['Id'].values\n",
    "test_id=test['Id']\n",
    "\n",
    "X_train=train.drop(['SalePrice','Id'],axis=1)\n",
    "X_test=test.drop(['Id'],axis=1)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据标准化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler\n",
    "ss_X = StandardScaler()\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_test)\n",
    "\n",
    "mean_y = y_train.mean()\n",
    "std_y = y_train.std()\n",
    "y_train = (y_train - mean_y)/std_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on train is 0.9286607655343642\n"
     ]
    }
   ],
   "source": [
    "#线性回归模型训练\n",
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.metrics import r2_score\n",
    "\n",
    "lr=LinearRegression()\n",
    "\n",
    "lr.fit(X_train,y_train)\n",
    "\n",
    "y_train_pred_lr=lr.predict(X_train)\n",
    "\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "\n",
    "print('The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFsCAYAAADlrTG7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAH5ZJREFUeJzt3XuUnFWZ7/HvA7SJQ7gYSTAkaIIDSLgl2AnJ4mI0KghI8CwRPAhBImEQZqmjHgXHQw9LZjkLRmc4MMygYLgpN8cDo3gGJgMrwhnQhJPJAOESlUiHGALIJSCXhOf88b4dKp1OutNdTWd3fz9r1eqqXbveeuoN1K/2fne9FZmJJEkqxzYDXYAkSdoyhrckSYUxvCVJKozhLUlSYQxvSZIKY3hLklQYw1uSpMIY3pJ6JSLeHhH/EhHPR8RNb+HznhsR39/M/Y9HxIeb8DynRsTdfd2O1B8Mbw16EXFXRPwhIoZ1ap8XERkRx3Zq/7u6/dT69qkRsS4i1nS67Fbff2hE/N86xJ6NiHsiYko3NXUZDM0KnrfIJ4FdgXdm5vGd74yItoh4vd5Xz9X7aHpfnzQz/zozP9fX7UglM7w1qEXEeOAwIIFju+jyKDC7of92wPHArzv1+4/MHNHp8m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LggULWL16Nbvtths/+9nPAHj++ec32M7KlSs577zzWLRoETvttBMf/OAHmTx5oy81bWD48OH85Cc/Yccdd+Tpp59m2rRpHHvssRss/PrhD3/IEUccwTe+8Q3WrVvHyy+/3KvX+fDDD3PnnXfy4osvsvfee3PmmWeybNkybrjhBu655x5aWlr4/Oc/z3XXXccpp5zCBRdcwMiRI1m3bh0zZ85kyZIlHHDAAevrvvvuu3tVx+YY3pKkzfrjH//IpEmTePzxx3n/+9/PRz7yEaAK79tvv3198K5Zs4bHHnuMww47jK985St87Wtf45hjjuGwww7bYHv33XcfM2bMoOPU2CeccAKPPvroZmvITM4991wWLFjANttsw4oVK1i1ahXvete71veZMmUKp512Gq+//jrHHXcckyZN6tXrPfrooxk2bBjDhg1j9OjRrFq1ivnz57No0SKmTJmyfp+MHj0agBtvvJHLL7+ctWvXsnLlSh566KH14X3CCSf0qobuOG0uSdqsjmPey5cv57XXXlt/zDszOeecc1i8eDGLFy9m2bJlzJkzh7322otFixax//77c84553D++edvtM1NfVVqu+2244033li//ddeew2A6667jtWrV7No0SIWL17MrrvuutFZ5w4//HAWLFjA2LFjOfnkk7n66qt79XqHDRu2/vq2227L2rVryUxmz569/rU+8sgjtLW18dvf/paLLrqI+fPns2TJEo4++ugN6tp+++17VUN3HHlLg1xPVyc3exWzBp+ddtqJiy++mFmzZnHmmWdyxBFH8M1vfpOTTjqJESNGsGLFClpaWli7di0jR47kM5/5DCNGjGDevHkbbOfggw/mC1/4As888ww77rgjN910EwceeCBQHSdetGgRn/rUp7jlllt4/fXXgWrqffTo0bS0tHDnnXeyfPnGv5y5fPlyxo4dy+mnn85LL73E/fffzymnnNKU1z5z5kxmzZrFl770JUaPHs2zzz7Liy++yAsvvMD222/PTjvtxKpVq/j5z3/OjBkzmvKcm2N4S1JBBvpD1uTJkznwwAO5/vrrOfnkk1m6dCnTp08HqsVl1157LcuWLeOrX/0q22yzDS0tLVx22WUbbGPMmDG0tbUxffp0xowZw0EHHbR+8dfpp5/OrFm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EDwH8DFgx0IaVqOH3xx4CJwKcjYuLAVjUozAOOHOgiBpG1wJczcx9gGnCW/52+yfDuR5l5e2aurW/eS/V9d/VBZi7NzMF2Nr632vrTF2fma0DH6YvVB5m5AHh2oOsYLDJzZWbeX19/EVgKjB3YqrYehvdb5zTg5wNdhET1BvhEw+12fFPUViwixgOTgfsGtpKtR7/9JOhQERH/Bryri7u+kZm31H2+QTUFdN1bWVuperJP1Sfdnr5Y2lpExAjgx8AXM/OFga5na2F491Fmfnhz90fEbOAYYGb6pfoe6W6fqs88fbGKEBEtVMF9XWb+80DXszVx2rwfRcSRwNeAYzPz5YGuR6p5+mJt9SIigCuApZn5nYGuZ2tjePevS4AdgDsiYnFE/ONAF1S6iPhERLQD04GfRcS/DnRNpakXUXacvngpcOMQPH1x00XEj4D/APaOiPaImDPQNRXuEOBk4EP1++fiiDhqoIvaWnh6VEmSCuPIW5KkwhjekiQVxvCWJKkwhrckSYUxvCVJKozhLUlSYQxvSZIK8/8B6/ff6D5HC+4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"AMES_House of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "看样子训练的模型好像挺好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on train is 0.9309061147802469\n"
     ]
    }
   ],
   "source": [
    "# 线性模型，随机梯度下降优化参数\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "sgdr.fit(X_train, y_train)\n",
    "\n",
    "print('The value of default measurement of SGDRegressor on train is', sgdr.score(X_train, y_train))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "好像比最小二乘回归结果更好一些"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on train is 0.8999109585907624\n"
     ]
    }
   ],
   "source": [
    "#岭回归 L2正则\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "alphas = [0.1,1,10,100,1000,10000]\n",
    "\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)\n",
    "\n",
    "ridge.fit(X_train, y_train)\n",
    "\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "print('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmcVPWZ7/HP0xvN1s3W0NDsOw0iaIsrogiImgDmZtFEs4wJk8z1Zh9jXuYmM+bOTCLXubmZqCNjnNzETBw1CRCD0UIQ3BgBQZRqkEWBpqG6kbVZGrr7uX9UNZZlN91In66qru/79eJF1Tm/U+cpkf5yfuec55i7IyIicjZZyS5ARERSn8JCRERapLAQEZEWKSxERKRFCgsREWmRwkJERFqksBARkRYFGhZmNtvMtpjZNjO7u4n13zazsJltNLPnzWxI3Lr7zGyTmZWb2c/NzIKsVUREmhdY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Oazaty9WxvVtQqY6+4H2+LzRJqjIwuR1nk69mCdPODH7r4PwN1PmNmPiD7HfFd7FhSbKvtnBYW0Bx1ZiIhIi3SCW0REWqSwEBGRFiksRESkRQoLERFpkcJCRERapLAQEZEW/X9f4EOcgiUDOAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 1000.0\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这个正则超参数有点大啊...不知道是否和特征维数太大有关"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on train is 0.9177849786454481\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHPxJREFUeJzt3Xl0XOd53/Hvg50EuAPgToGUSFBcLQdaLGqjFhsiaenYjSMrcRIvsZoeu3Yap7Ed9UiNfXJOT9SmrV05jeq4bhrHqhM7sTSgJEsiJdqyZZGSzOEGUhC1kMKAADcQJIh1nv4xg/EIBIkhhTt3lt/nHB7g3nln7jOHA/xwn/vOO+buiIiIAJSEXYCIiOQOhYKIiKQoFEREJE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iKS8v8BHS0bJpypziIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.01\n"
     ]
    }
   ],
   "source": [
    "#Lasso回归 L1正则\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "alphas = [0.001,0.01,0.1,1,10,100,]\n",
    "\n",
    "lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "lasso.fit(X_train, y_train)\n",
    "\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "print('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))\n",
    "\n",
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为什么lasso的正则这么小，和L2的差太多\n",
    "将测试集的结果输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "#最小二乘回归结果\n",
    "y_test_pred_lr=y_test_pred_lr * std_y +  mean_y\n",
    "#岭回归\n",
    "y_test_pred_ridge=y_test_pred_ridge * std_y +  mean_y\n",
    "#Lasso回归\n",
    "y_test_pred_lasso=y_test_pred_lasso * std_y +  mean_y\n",
    "\n",
    "\n",
    "y_test=pd.DataFrame([y_test_pred_lr,y_test_pred_ridge,y_test_pred_lasso]).T\n",
    "y_test.columns=['y_test_pred_lr','y_test_pred_ridge','y_test_pred_lasso']\n",
    "y_test=pd.concat([test_id,y_test],axis=1)\n",
    "\n",
    "y_test.to_csv('HW1_AMES_House_pre.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
